import 'package:yqmssa_app/request/http_path.dart';
import 'package:yqmssa_app/request/my_request.dart';

import 'banner_data_model.dart';

class IndexRequest {
  IndexRequest._();

  static Future<List<VideoListDM>> vL() async {
    final data = {
      "page": 1,
      "pagesize": "10",
    };
    final res = await MyRequest().dioReq(HttpPath.videoListPath, data: data);
    return VideoListDM.fromList(res["data"] ?? []);
  }

  static Future<List<LunDM>> bL() async {
    final res = await MyRequest().dioReq(HttpPath.lunList);
    return LunDM.fromList(res["data"] ?? []);
  }

  static Future<VideoDetailDataModel> vD(int id) async {
    final data = {
      "video_id": "$id",
    };
    final res = await MyRequest().dioReq(HttpPath.dt, data: data);
    return VideoDetailDataModel.fromJson(res["data"]);
  }

  static Future<String> serviceContent() async {
    final res = await MyRequest().dioReq(HttpPath.serviceContent);
    return res["data"]["content"] ?? "";
  }
}

class VideoListDM {
  late final int id;
  late final String title;
  late final String fengImage;
  late final List<String> tags;
  late final int bmNum;
  late final String subtitle;
  late final int price;
  late final String payType;
  late final int sort;
  late final String videofile;
  late final String tagsStr;

  static fromList(List json) {
    return List.from(json).map((e) => VideoListDM.fromJson(e)).toList();
  }

  VideoListDM.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    title = json['title'];
    fengImage = json['feng_image'];
    tags = List.castFrom<dynamic, String>(json['tags']);
    bmNum = json['bm_num'];
    subtitle = json['subtitle'];
    price = json['price'];
    payType = json['pay_type'];
    sort = json['sort'];
    videofile = json['videofile'];
    tagsStr = json['tags_str'];
  }
}

class VideoDetailDataModel {
  VideoDetailDataModel({
    this.list,
    this.video,
    this.btnDefault = "",
    this.title = "",
    this.adminId = 0,
    this.fullName = "",
    this.statementTitle = "",
    this.statementContent = "",
  });

  List<ListData>? list;
  VideoData? video;
  late String btnDefault;
  late String title;
  late int adminId;
  late String fullName;
  late String statementTitle;
  late String statementContent;

  VideoDetailDataModel.fromJson(Map<String, dynamic> json) {
    list = List.from(json['list']).map((e) => ListData.fromJson(e)).toList();
    video = VideoData.fromJson(json['video'] is Map ? json['video'] : {});
    btnDefault = json['btn_default'];
    title = json['title'] ?? "";
    adminId = json['admin_id'];
    fullName = json['full_name'];
    statementTitle = json['statement_title'];
    statementContent = json['statement_content'];
  }
}

class ListData {
  ListData({
    required this.id,
    required this.money,
  });

  late final int id;
  late final String money;

  ListData.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    money = json['money'];
  }
}

class VideoData {
  VideoData({
    this.workType = 0,
    this.limitPlace = "",
    this.limitAgeRange = "",
    this.status = "",
    this.id = 0,
    this.title = "",
    this.videofile = "",
    this.fengImage = "",
    this.twiceImg = "",
    this.boNumber = 0,
    this.introduceImage = "",
    this.isJumpMiniprogram = 0,
    this.isJumpWeb = 0,
    this.minAge = 0,
    this.advOrigin = "",
  });

  late int workType;
  late String limitPlace;
  late String limitAgeRange;
  late String status;
  late int id;
  late String title;
  late String videofile;
  late String fengImage;
  late String twiceImg;
  late int boNumber;
  late String introduceImage;
  late int isJumpMiniprogram;
  late int isJumpWeb;
  late int minAge;
  late String advOrigin;

  VideoData.fromJson(Map<String, dynamic> json) {
    workType = json['work_type'];
    limitPlace = json['limit_place'];
    limitAgeRange = json['limit_age_range'];
    status = json['status'];
    id = json['id'];
    title = json['title'];
    videofile = json['videofile'];
    fengImage = json['feng_image'];
    twiceImg = json['twice_img'];
    boNumber = json['bo_number'];
    introduceImage = json['introduce_image'];
    isJumpMiniprogram = json['is_jump_miniprogram'];
    isJumpWeb = json['is_jump_web'];
    minAge = json['min_age'];
    advOrigin = json['adv_origin'];
  }
}
